import Taro from '@tarojs/taro';
export function markPhone(phone:string){
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}

export function isLogin(){
  return Taro.getStorageSync('token') && Taro.getStorageSync('openid') && Taro.getStorageSync('whToken') && Taro.getStorageSync('user')
}
export function getRoleValue(value){
  let rule = 1
  switch (value) {
    case '爸爸':
      rule = 1;
      break;
    case '妈妈':
      rule = 2;
      break;
    case '儿子':
      rule = 3;
      break;
    case '女儿':
      rule = 4;
      break;
    case '丈夫':
      rule = 5;
      break;
    case '妻子':
      rule = 6;
      break;
  }
  return rule
}
export function getRoleName(value){
  let name = ''
  value = value.toString()
  switch(value){
    case '1':
      name = '爸爸';
      break;
    case '2':
      name = '妈妈';
      break;
    case '3':
      name = '儿子';
      break;
    case '4':
      name = '女儿';
      break;
    case '5':
      name = '丈夫';
      break;
    case '6':
      name = '妻子';
      break;
    default:
      name = '其他';
      break;
  }
  return name
}

export function goOrderDrugMiniProgram(){
  console.log('goOrderDrugMiniProgram')
  let token = Taro.getStorageSync('token')
  let whToken = Taro.getStorageSync('whToken')
  let patientId = Taro.getStorageSync('patientId')
  console.log('token:',token)
  console.log('whToken:',whToken)
  console.log('patientId:',patientId)
  if(token && whToken && patientId){
    Taro.navigateToMiniProgram({
      appId: 'wx2db0b20b87789f11',
      path: 'pages/cityDrugStore/index',
      extraData: {
        token,
        whToken,
        patientId
      },
      envVersion: 'trial',
      success(res) {
        // 打开成功
        console.log(res)
      }
    })
  }else {
    console.log('未登录，跳转到积分宝小程序')
    Taro.navigateToMiniProgram({
      appId: 'wx2db0b20b87789f11',
      path: 'pages/cityDrugStore/index',
      envVersion: 'trial',
      success(res) {
        // 打开成功
        console.log(res)
      }
    })
    // wx.showToast({
    //   title: '请先登录',
    //   icon: 'none',
    //   duration: 2000
    // })
  }
}